<?php include "./pc/view/header.inc.htm"; ?>

<?php if($isfirst) { ?>
<div class="container">
    <div class="addtopic">
        <form method="POST" id="post_update_form_<?php echo $pid; ?>" action="post-update-<?php echo $pid; ?>.htm">
        <div class="content-header">
            <div class="tw-header-inner">
                <div class="select-box">
                    <span class="forum_select"></span>
                </div>
                <input class="form-control" type="text" placeholder="标题" name="subject" value="<?php echo $thread['subject']; ?>" style="width:450px;">
            </div>
        </div>
        <div class="content-post">
            <div class="post-inner">
                <textarea class="input-body" id="post_update_message" name="message" placeholder="内容" style="width: 93%; height: 300px;"><?php echo $post['message']; ?></textarea>
                <div class="post-button-left mt15">
                    <button class="Button Button--primary" type="button" loading-text="正在提交...">
                        <span class="submit-button-text">编辑帖子</span>
                    </button>
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>
</div>

<?php } else {?>
<div class="container">
    <div class="addtopic" id="post_create_dl">
        <form method="POST" id="post_update_form_<?php echo $pid; ?>" action="post-update-<?php echo $pid; ?>.htm">
        <div class="content-header">
            <div class="tw-header-inner">
                编辑帖子内容
            </div>
        </div>
        <div class="content-post">
            <div class="post-inner">
                <textarea class="input-body" id="post_update_message" name="message" placeholder="内容" style="width: 93%; height: 280px;"><?php echo $post['message']; ?></textarea>
                <div class="post-button-left mt15">
                    <button class="Button Button--primary" type="button" loading-text="正在提交...">
                        <span class="submit-button-text">编辑帖子</span>
                    </button>
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>
</div>
<?php } ?>

<?php include "./pc/view/footer.inc.htm"; ?>

<link rel="stylesheet" type="text/css" href="xneditor/editor.css" />

<script src="xiunoui/async.js"></script>
<script src="xiunoui/upload.js"></script>
<script src="xneditor/editor.js"></script>
<script>

var editor = new $.XNEditor({textarea: 'post_update_message', image_upload_url:'post-upload-1.htm', image_upload_width: <?php echo $conf['upload_image_width']; ?>, file_upload_url:'post-upload-0.htm'});

var jform = $('#post_update_form_<?php echo $pid; ?>');
var jmessage = jform.find('textarea');
var jseo_url = jform.find('input[name="seo_url"]');
var jsubmit = jform.find('button').filter('[type="button"]');

// 选择论坛
var fid = <?php echo $fid; ?>;
var pid = <?php echo $pid; ?>;
var tid = <?php echo $tid; ?>;
var isfirst = <?php echo $isfirst; ?>;
var jforum_select = jform.find('span.forum_select');
var forumarr = <?php echo $forumarr; ?>;
var s = '<select name="fid">'; $.each(forumarr, function(k, v) { s += '<option value="'+k+'">'+v+'</option>'}); s += '</select>';
var jselect = jforum_select.html(s).find('select');
jselect.checked(fid);

jsubmit.off('click').on('click', function() {
    if(!jmessage.val()) {
        editor.jeditor.popover('请输入内容');
        editor.focus();
        return false;
    }
    jsubmit.button('loading');
    var postdata = jform.serializeObj();
    $.xpost(jform.attr('action'), postdata, function(code, message) {
        if(code == 0) {
            jsubmit.button('编辑成功');
            setTimeout(function() {editor.clear(); window.location='<?php echo $thread['url'];?>';}, 1000);
            return;
        } else if(code == 2) {
            jmessage.popover(message).focus();
        } else if(code == 4) {
            jseo_url.popover(message).focus();
        } else {
            $.alert(message);
        }
        jsubmit.button('reset');
    });
    
    return false;
});

// 快捷键回复
jform.keyup(function(e) {
    if((e.ctrlKey && (e.which == 13 || e.which == 10)) || (e.altKey && e.which == 83)) {
        jsubmit.trigger('click');
        return false;
    }
});
</script>